Skip to content

refactor(chartverifier): simplify GetPackageDigest and document helpers#608

Merged
komish merged 1 commit into
redhat-certification:mainfrom
caxu-rh:fix-reportbuilder-close
May 28, 2026
Merged

refactor(chartverifier): simplify GetPackageDigest and document helpers#608
komish merged 1 commit into
redhat-certification:mainfrom
caxu-rh:fix-reportbuilder-close

Conversation

@caxu-rh

@caxu-rh caxu-rh commented May 11, 2026

Copy link
Copy Markdown
Contributor

Extract openChartPackageReader for clearer scheme handling and a single defer rc.Close() on success. Propagate os.Open errors instead of ignoring them. Add godoc for GetPackageDigest and openChartPackageReader.

@github-actions

Copy link
Copy Markdown

Thanks for your pull request!

A maintainer will review this pull request and trigger functional testing by adding the ok-to-test label.

This comment was auto-generated by GitHub Actions.

@komish komish added the ok-to-test Used after code review to run E2E/integration tests. label May 27, 2026
Comment thread internal/chartverifier/reportBuilder.go Outdated
Comment thread internal/chartverifier/reportBuilder.go Outdated
Comment on lines +226 to +230
// openChartPackageReader opens the chart package byte stream at u for digesting.
// On success, it returns an [io.ReadCloser]: for http or https, the response body from [http.Get];
// for file or an empty scheme, the file from [os.Open] when the URL path ends with ".tgz".
// It returns (nil, nil) for file or an empty scheme when the path does not end with ".tgz".
// It returns (nil, err) if the scheme is unsupported, or if [http.Get] or [os.Open] fails.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels redundant, seeing it both in the exported Function as well as here, even though they have subtle differences. Can we figure out a way to make sure the comments don't overlap as heavily?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, feels a little too specific by providing exact error case tuples as references. Better to capture the behavior at a higher level, and leave the return cases as something that can be observed by reading the logic itself, given it isn't very long.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've shortened/condensed the godoc in both functions.

Comment thread internal/chartverifier/reportBuilder.go Outdated

@komish komish left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments. Overall, I'm not sure if we're getting too much here given we don't really enrich or use any of the errors that would be returned by the new function, but if you believe it's more readable, we can merge this after the requested changes.

@caxu-rh caxu-rh force-pushed the fix-reportbuilder-close branch from 960b797 to 417e5b8 Compare May 28, 2026 15:06
@github-actions github-actions Bot removed the ok-to-test Used after code review to run E2E/integration tests. label May 28, 2026
@caxu-rh

caxu-rh commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. The goal was originally to ensure that reader (file or response body) gets closed, but due to the early-return style it would've required multiple defer in the lines above, hence the larger refactor. If it feels like too much, we can still keep the original, just need to have some more in each case.

Extract openChartPackageReader for clearer scheme handling and a single
defer rc.Close() on success. Propagate os.Open errors instead of ignoring
them. Add godoc for GetPackageDigest and openChartPackageReader.

Co-authored-by: Cursor <cursoragent@cursor.com>
@caxu-rh caxu-rh force-pushed the fix-reportbuilder-close branch from 417e5b8 to f78fa15 Compare May 28, 2026 15:56
@komish komish added the ok-to-test Used after code review to run E2E/integration tests. label May 28, 2026

@komish komish left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@komish komish merged commit 384775a into redhat-certification:main May 28, 2026
16 checks passed
@github-actions github-actions Bot removed the ok-to-test Used after code review to run E2E/integration tests. label May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants